<script>
	export default {
		onLaunch: function() {
			console.log('App Launch')
			const HC_names = uni.getStorageSync('HC_name');
			if(HC_names!=''){
				uni.switchTab({
					url: '/pages/index/index'
				});
			}else{
				uni.showToast({
					title: '请先登录',
					mask: true,
					icon: "none"
				
				});
				
			}
		},
		onShow: function() {
			// #ifdef APP-PLUS
			this.notificationToGo();
			// #endif
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		globalData: {
			testJson: {
				messageId: '',
				content: '',
			},
			yaoshang:{},
			// 监听到有新服务器消息
			getSocketMsg(reData) {
				// 监听到服务器消息
				// console.log('收到服务器消息', reData);
				// console.log(reData,"dd")
				const data = JSON.parse(reData)
				try {
					const data1 = JSON.parse(data.msg)
					 if (data.msgType=="pension.com.alarm.entity.Alarm") {
						  console.log('收到服务器消息', reData);
						    this.homeName=data1.houseNo
							this.groupHouseNo=uni.getStorageSync("house")
							var HouseNo=this.groupHouseNo.split(',')
							//循环判断是否是登录人的房间号
							for(let i = 0;i<HouseNo.length;i++){
								if(this.homeName==HouseNo[0]){
									// console.log('收到服务器消息1', reData);
									if(data1.devName=="sos报警"){
										this.content =data1.memberName+data1.alarmDetail
									}else{
										this.content =data1.houseNo+data1.devName+data1.alarmDetail
									}
									if(data1.status=="1"){
										this.content=this.content+"已解除警告"
									}
								}
								}
						
					}else if (data.msgType=="com.core.healthNotify.controller.HealthNotifyController.health.notice") {
						this.whether=true
						this.content=data1.name+"膳食提醒"
						console.log(this.content);
					}else {
						return
					}
					this.msgType=data.msgType
				} catch (e) {
					// console.log('收到错误消息', e);
				}
				if (data.code == "99") {
					if (data.msg != 'ping') {
						console.log('收到服务器消息1', reData);
							this.testJson.messageId = this.messageId
							this.testJson.content = this.content
							// #ifdef APP-PLUS
							const module = uni.requireNativePlugin("WT-PushModule");
							// console.log(module)
							const n = module.appPush({
								notificationArray: this.testJson
							});
							console.log(n)
							// #endif
							}
						}
			},
		},
		methods:{
		notificationToGo() {
			if (plus.runtime.arguments != "" && plus.runtime.arguments != null) {
				const androidIntent = JSON.parse(plus.runtime.arguments);
				const NotificationUrl = Object.values(androidIntent);
				console.log(NotificationUrl)
				uni.navigateTo({
					url: NotificationUrl[0]
				});
				plus.runtime.arguments = null
		
			}
		},
		}
	}
</script>

<style>
	/*每个页面公共css */
	/* 背景颜色 #EBEFF6 */
	page {
		background-color: #F3F3F3;
	}
	/* 苹方字体 */
	@font-face {
		font-family: 'ppf';
		src: url('~@/static/font/pf.ttf');
	}
	
	* {
		font-family: 'ppf';
	}
	/* 提交按钮样式 */
	.sub_button {
		height: 38px;
		width: 90.6%;
		background-color: #da422a;
		color: #FFFFFF;
		line-height: 38px;
		text-align: center;
		margin: 48px auto 0 auto;
		border-radius: unset;
	}
	.uni-icons span {
		font-family: UniIcons;
	}
</style>
